using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ExpertSMS.Models;

namespace ExpertSMS.Controllers
{   
    public class MakeFoodsController : Controller
    {
        private ExpertSMSContext context = new ExpertSMSContext();

        //
        // GET: /MakeFoods/

        public ViewResult Index()
        {
            return View(context.MakeFoods.Include(makefood => makefood.Kitchen).Include(makefood => makefood.Food).Include(makefood => makefood.MakeFoodProducts).ToList());
        }

        //
        // GET: /MakeFoods/Details/5

        public ViewResult Details(int id)
        {
            MakeFood makefood = context.MakeFoods.Single(x => x.MakeFoodID == id);
            return View(makefood);
        }

        //
        // GET: /MakeFoods/Create

        public ActionResult Create(int kitchenID,int foodID)
        {
            ViewBag.Kitchen = context.Kitchens.FirstOrDefault(x=>x.KitchenID == kitchenID);
            ViewBag.Food = context.Foods.FirstOrDefault(x=>x.FoodID == foodID);
            return View();
        } 

        //
        // POST: /MakeFoods/Create

        [HttpPost]
        public ActionResult Create(MakeFood makefood)
        {
            if (ModelState.IsValid)
            {
                context.MakeFoods.Add(makefood);
                context.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.PossibleKitchens = context.Kitchens;
            ViewBag.PossibleFoods = context.Foods;
            return View(makefood);
        }
        
        //
        // GET: /MakeFoods/Edit/5
 
        public ActionResult Edit(int id)
        {
            MakeFood makefood = context.MakeFoods.Single(x => x.MakeFoodID == id);
            ViewBag.PossibleKitchens = context.Kitchens;
            ViewBag.PossibleFoods = context.Foods;
            return View(makefood);
        }

        //
        // POST: /MakeFoods/Edit/5

        [HttpPost]
        public ActionResult Edit(MakeFood makefood)
        {
            if (ModelState.IsValid)
            {
                context.Entry(makefood).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.PossibleKitchens = context.Kitchens;
            ViewBag.PossibleFoods = context.Foods;
            return View(makefood);
        }

        //
        // GET: /MakeFoods/Delete/5
 
        public ActionResult Delete(int id)
        {
            MakeFood makefood = context.MakeFoods.Single(x => x.MakeFoodID == id);
            return View(makefood);
        }

        //
        // POST: /MakeFoods/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            MakeFood makefood = context.MakeFoods.Single(x => x.MakeFoodID == id);
            context.MakeFoods.Remove(makefood);
            context.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}